package com.tencent.wuyanzu.action;

import java.util.ArrayList;

import org.apache.struts2.json.annotations.JSON;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;
import com.tencent.wuyanzu.model.Food;
import com.tencent.wuyanzu.service.TestService;

public class TestAction extends ActionSupport{
	
	@Autowired
	private TestService testService;

	private int uid;
	private ArrayList<Integer> selectedFid;
	
	private ArrayList<Food> food;
	
	@Override
	public String execute() throws Exception {
		int choice = 0;
		for(Integer each : selectedFid){
			choice += Math.pow(2, each-1);
		}
		testService.submitTest(uid, choice);
		return super.execute();
	}

	//----------------------- post请求参数 -----------------------
	@JSON(serialize=false)
	public int getUid() {
		return uid;
	}

	public void setUid(int uid) {
		this.uid = uid;
	}

	@JSON(serialize=false)
	public ArrayList<Integer> getSelectedFid() {
		return selectedFid;
	}

	public void setSelectedFid(ArrayList<Integer> selectedFid) {
		this.selectedFid = selectedFid;
	}
	
	//----------------------- 返回值 -----------------------
	
	@JSON(serialize=true)
	public ArrayList<Food> getFood() {
		return food;
	}
}
